package com.bilibili.xzz.controller;

import com.bilibili.xzz.entity.Background;
import com.bilibili.xzz.service.BackgroundService;
import com.bilibili.xzz.utils.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/api/image")
public class BackgroundController {

    @Resource
    BackgroundService backgroundService;

    @PostMapping("/img")
    public Result Image() {
        try {
            List<Background> backgroundList = backgroundService.getAllImage();
            int num = (int) (Math.random()*backgroundList.size());
            return Result.ok().data("img", backgroundList.get(num));
        } catch (Exception e) {
            return Result.error().data("msg", "获取图片信息失败");
        }

    }
}
